//
//  QRCodeCreateViewController.swift
//  新浪微博
//
//  Created by 李赛 on 15/5/18.
//  Copyright (c) 2015年 李赛. All rights reserved.
//

import UIKit

class QRCodeCreateViewController: UIViewController {

    @IBOutlet weak var iconImage: UIImageView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        createQRCode()
    }
    
    private func createQRCode(){
        // 简建立一个滤镜
        let qrfilter = CIFilter(name: "CIQRCodeGenerator")
        // 建立滤镜的初始值
        qrfilter.setDefaults()
        // 通过KVC设置滤镜的内容
        
//        qrfilter.setValue("我就是你大哥".dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false), forKey: "inputMessage")
        qrfilter.setValue("大腿,棒棒的!".dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false), forKey: "inputMessage")
        // 输出图像
        let outImg = qrfilter.outputImage
        
        let colorFilter = CIFilter(name: "CIFalseColor")
        colorFilter.setDefaults()
        colorFilter.setValue(outImg, forKey: "inputImage")
        colorFilter.setValue(CIColor(red: 0.1, green: 0.4, blue: 0.9), forKey: "inputColor0")
        colorFilter.setValue(CIColor(red: 1, green: 0.5, blue: 0.8), forKey: "inputColor1")
        let transform = CGAffineTransformMakeScale(5, 5)
        let transImg = colorFilter.outputImage.imageByApplyingTransform(transform)
        
        // 显示图像
        iconImage.image = UIImage(CIImage: transImg)
        
        
    }
}
